unit frmHint;



interface

 uses
  Windows,StdCtrls,ExtCtrls,Messages, SysUtils, Variants, Classes,Controls,Forms,Graphics,
   WinTypes, WinProcs;
type TlbrToolTip = class (TCustomPanel)
    private
      fOwner: TControl;
      fPen: TPen;
      fBrush: TBrush;
      fText: String;
      fShown: Boolean;
      procedure SetText(const Value: String);
    protected
      procedure Paint; override;
      procedure PerformClick(Sender: TObject);
    public
      constructor Create(aOwner: TComponent); override;
      destructor Destroy; override;
      property Shown: Boolean read fShown; //If true then at some point the tooltip has been shown.
    published
      procedure StyleChanged(Sender: TObject);
      procedure Show;
      procedure Hide;
      procedure Reset(Sender: TObject); //Sets shown to false.
      property Text: String read fText write SetText;
      property OnClick;
    end;

implementation

{ TlbrToolTip }

procedure TlbrToolTip.PerformClick(Sender: TObject);

begin
  Visible:=False;
end;

constructor TlbrToolTip.Create(aOwner: TComponent);
begin

//----------------------------------------------------------------
  inherited Create(AOwner);
  visible:=false;
  ControlStyle := ControlStyle + [csReplicatable, csNoDesignVisible];
  fOwner:=(aOwner as TControl);
  Width := 65;
  Height := 28;
  FPen := TPen.Create;
  FPen.OnChange := StyleChanged;
  FBrush := TBrush.Create;
  FBrush.Color:=clRed;
  FBrush.OnChange := StyleChanged;
  OnClick:=PerformClick;
//------------------------------------


end;

destructor TlbrToolTip.Destroy;
begin
  FPen.Free;
  FBrush.Free;
  inherited Destroy;
end;

procedure TlbrToolTip.Hide;
begin
  visible:=False;
end;

procedure TlbrToolTip.Paint;
var
  X, Y, W, H, S, tw, th: Integer;
begin
  with Canvas do begin
    Pen := FPen;
    Brush := FBrush;
    X := Pen.Width div 2;
    Y := X;
    W := Width - Pen.Width + 1;
    H := Height - 7;
    if Pen.Width = 0 then
    begin
      Dec(W);
      Dec(H);
    end;
    if W < H then S := W else S := H;
    RoundRect(X, Y, X + W, Y + H, S div 4, S div 4);
    th:=TextHeight(fText);
    tw:=TextWidth(fText);
    TextOut((Self.width-tw) div 2,(Self.Height-th-5) div 2,fText);
  end;
  with Canvas do begin
    Pen := FPen;
    Brush := FBrush;

    X := 10 div 2;
    Y := 10;
    W := 20 ;
    H := 10;
    if Pen.Width = 0 then begin
      Dec(W);
      Dec(H);
    end;
     //desenhar triangulo
  end;
end;

procedure TlbrToolTip.Reset(Sender: TObject);
begin
  visible:=False;
  fShown:=False;
end;

procedure TlbrToolTip.SetText(const Value: String);
begin
  fText := Value;
  Canvas.Font.color := $00F8F8F8;
  Width := Length(Value)+6+ Canvas.TextWidth(fText);
  Invalidate;


end;

procedure TlbrToolTip.Show;
var
  l,t: integer;
begin
  if not fShown and not (csDesigning in ComponentState) then
    begin
    l:=fOwner.Left+90;
    t:=fOwner.Top+fOwner.Height+2-55;
    if (l+self.Width>fOwner.Parent.ClientWidth) then
      l:=fOwner.Parent.ClientWidth-self.Width-(fOwner.Width-fOwner.ClientWidth);
    if (t+self.Height>fOwner.Parent.ClientHeight) then
      t:=fOwner.Top-self.Height-2;
    Left:=l;
    Top:=t;
    
    BringToFront;
    Visible:=true;
    end;
  fShown:=True;

end;

procedure TlbrToolTip.StyleChanged(Sender: TObject);
begin
  Invalidate;
end;


end.

